home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / Xprof / xprof / event.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  4KB  |  115 lines

  1. /*==================================================================
  2.  *      File :          event.c
  3.  *      Package:        Xprof
  4.  *
  5.  *      Author :        Aloke Gupta.
  6.  *
  7.  *  (C) Copyright 1992, Aloke Gupta.
  8.  *==================================================================*/
  9.  
  10. /*
  11.  * Processing routines for the events seen in the message stream.
  12.  * Functions:
  13.  *    1. process_event(FILE *fp, char *string, GlobalStats *gstats)
  14.  *    2. print_event_stats(FILE *fp)
  15.  *    3. The routines to process each event seen. These have the format:
  16.  *           Event(FILE *fp, event_index, current_time)
  17.  */
  18.  
  19. #include <stdio.h>
  20. #include "common.h"
  21.  
  22. MsgStats TotalEventStats;        /* Overall stats for all events */
  23. MsgStats EventStats[MAXEVENTS];        /* Detailed stats for each event */
  24.  
  25. /*static char in_string[MAXSTRINGSIZE];*/ /* Buffer to read a record into */
  26. static char sbuf[132];            /* Temp. slots for sscanf*/
  27.  
  28. extern MsgType EventType[];
  29. extern int lookup_event();
  30.  
  31. process_event(fp, string, gstats)
  32. FILE *fp;
  33. char *string;
  34. GlobalStats *gstats;
  35. {
  36.     char event_name[80];        /* Name of the current event */
  37.     int event_index;            /* Index in the data structures*/
  38.     long bytes=0;            /* Number of bytes */
  39.  
  40.     if (TotalEventStats.invoked == FALSE)
  41.         InitMsgStats(&TotalEventStats, gstats->current_time, DETAILED, GRAIN1);
  42.  
  43.     sscanf(string, "%s %s",sbuf, event_name);
  44.     event_index = lookup_event(event_name);
  45.  
  46.     /* Call the action for this event */
  47.     bytes=EventType[event_index].action(fp, event_index, gstats->current_time);
  48.  
  49.     /*
  50.      * Fill the data structures for all the events.
  51.      */
  52.     FillMsgStats(&TotalEventStats, gstats->current_time, bytes, bytes);
  53.  
  54.     gstats->event_bytes += bytes;
  55.  
  56. }
  57.  
  58. print_event_stats(fp)
  59. FILE *fp;
  60. {
  61.     int i;
  62.     static char *dashes = {
  63.         "---------------------------------------------------------------"};
  64.  
  65.     if (TotalEventStats.invoked == FALSE)
  66.         return;
  67.     /*
  68.      * Print the details for all Events together 
  69.      */
  70.     PrintMsgStats(fp,&TotalEventStats, "EVENTS ");
  71.  
  72.     /*
  73.      * Brief table for the numbers and byte totals for the events
  74.      */
  75.     fprintf(fp,"\t%s\n", dashes);
  76.     fprintf(fp,"%-25s",  "        EVENT  messages");
  77.     fprintf(fp,"%25s",  "Total Bytes      ");
  78.     fprintf(fp," %19s\n","Number      ");
  79.     fprintf(fp,"\t%s\n", dashes);
  80.     for (i = 0; i < MAXEVENTS; i++)
  81.       if (EventStats[i].invoked == TRUE) {
  82.     fprintf(fp,"%-25s", EventType[i].name);
  83.     fprintf(fp," %10ld bytes",EventStats[i].total_bytes);
  84.     fprintf(fp," (%5.2f%%)", (float) 100 * EventStats[i].total_bytes / 
  85.                 TotalEventStats.total_bytes);
  86.     fprintf(fp," %10ld", EventStats[i].number );
  87.     fprintf(fp," (%5.2f%%)", (float) 100 * EventStats[i].number / 
  88.                 TotalEventStats.number);
  89.         fprintf(fp,"\n");
  90.     }
  91.     fprintf(fp,"\t%s\n", dashes);
  92.     fprintf(fp,"%25s"," Grand Total      ");
  93.     fprintf(fp," %10ld bytes         ", TotalEventStats.total_bytes);
  94.     fprintf(fp," %10ld         \n", TotalEventStats.number);
  95.     fprintf(fp,"\t%s\n", dashes);
  96.     if (verboselevel > 0) {
  97.     for (i = 0; i < MAXEVENTS; i++)
  98.       if (EventStats[i].detailed == DETAILED) 
  99.           PrintMsgStats(fp,&EventStats[i], EventType[i].name);
  100.     }
  101.     /*
  102.      * Now dump the raw statistics for the messages
  103.      */
  104.     if (verboselevel > 1) {
  105.     if (TotalEventStats.detailed == DETAILED)
  106.               PrintMsgDetails(fp,&TotalEventStats, "EVENTS ");
  107.  
  108.     for (i = 0; i < MAXEVENTS; i++)
  109.       if (EventStats[i].detailed == DETAILED) 
  110.           PrintMsgDetails(fp,&EventStats[i], EventType[i].name);
  111.     }
  112.     return;
  113. }
  114.  
  115.